package com.geeguo.ebuilder.client.base.database.proxy.impl;

import com.geeguo.ebuilder.client.base.database.model.DataSourceInfo;
import com.geeguo.ebuilder.client.base.database.model.DataSourceInfoConverter;
import com.geeguo.ebuilder.client.base.database.model.DataSourceInfoRO;
import com.geeguo.ebuilder.client.base.database.proxy.DataSourceInfoProxy;
import com.geeguo.ebuilder.client.base.database.remote.DataSourceInfoApi;
import com.geeguo.ebuilder.core.common.action.ActionResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class DataSourceInfoProxyImpl implements DataSourceInfoProxy {

    @Autowired
    private DataSourceInfoApi dataSourceInfoApi;
    
    @Override
    public DataSourceInfo get(String id) {
        ActionResult<DataSourceInfoRO> actionResult = dataSourceInfoApi.get(id);
        if (actionResult.isSuccess()) {
            DataSourceInfoRO dataSourceInfo = actionResult.getData();
            if (dataSourceInfo != null) {
                return DataSourceInfoConverter.INSTANCE.convert2Info(dataSourceInfo);
            }
        }
        return null;
    }
}